<?php
$isadmin=1;
include('check.php');
define('DUODUOROOT', ereg_replace("[/\\]{1,}", '/', dirname(dirname(__FILE__))));
define('DUODUODATA', DUODUOROOT . '/data/bdata');

if(!is_dir(DUODUODATA)){
    mkdir(DUODUODATA);
}

$cfg_backup_dir = 'backupdata';

include('../comm/conn.php');

$cfg_link = mysql_connect($dbserver, $dbuser, $dbpass);
mysql_select_db($dbname);
mysql_query("set names utf8");

$ss='!@455#6$%^&*(89)_+754af33gttdyuh';
$cfg_cookie_encode='';
for($i=0;$i<10;$i++){
	$j=rand(0,31);
    $cfg_cookie_encode.=$ss{$j};
}

get2var();
post2var();

function sel_date(){
    $dh = dir(DUODUODATA);
    $j=0;
    while(($filename=$dh->read()) !== false){
	    if ($filename != "." && $filename != ".."){
			$dp=DUODUODATA.'/'.$filename;
			if(judge_empty_dir($dp)!=1){
			    $arr=explode('_',$filename);
	            $time=date('Y-m-d',strtotime($arr[1]));
	            $option_arr[$j]="<option value='$arr[1]'>$time</option>";
		        $j++;
			}
	    }
    }
    for($i=$j;$i>=0;$i--){
        $option.=$option_arr[$i];
    }
    $dh->close();
	return $option;
}

function GetVersion($isformat = true) {
	$rs = mysql_query("SELECT VERSION();");
	$row = mysql_fetch_array($rs);
	$mysql_version = $row[0];
	mysql_free_result($rs);
	if ($isformat) {
		$mysql_versions = explode(".", trim($mysql_version));
		$mysql_version = number_format($mysql_versions[0] . "." . $mysql_versions[1], 2);
	}
	return $mysql_version;
}

function TjCount($tbname) {
	$sql = "Select count(*) as dd From $tbname";
	$query = mysql_query($sql);
	$row = mysql_fetch_array($query);
	return $row['dd'];
}

function PutInfo($msg1,$msg2){
	$msginfo = "<html>\n<head>
		<meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
		<title>duoduo提示信息</title>
		<base target='_self'/>\n</head>\n<body leftmargin='0' topmargin='0'>\n<center>
		<br/>
		<div style='width:400px;padding-top:4px;height:24;font-size:10pt;border-left:1px solid #cccccc;border-top:1px solid #cccccc;border-right:1px solid #cccccc;background-color:#DBEEBD;'>duoduo提示信息</div>
		<div style='width:400px;height:100px;font-size:10pt;border:1px solid #cccccc;background-color:#F4FAEB'>
		<span style='line-height:160%'><br/>{$msg1}</span>
		<br/><br/></div>\r\n{$msg2}";
	echo $msginfo."</center>\n</body>\n</html>";
}

function ShowMsg($msg, $gourl, $onlymsg = 0, $limittime = 0) {
	$htmlhead = "<html>\r\n<head>\r\n<title>duoduo提示信息</title>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />\r\n";
	$htmlhead .= "<base target='_self'/>\r\n<style>div{line-height:160%;}</style></head>\r\n<body leftmargin='0' topmargin='0'>\r\n<center>\r\n<script>\r\n";
	$htmlfoot = "</script>\r\n</center>\r\n</body>\r\n</html>\r\n";
	$litime = ($limittime == 0 ? 1000 : $limittime);
	$func = '';

	if ($gourl == '-1') {
		if ($limittime == 0)
			$litime = 5000;
		$gourl = "javascript:history.go(-1);";
	}

	if ($gourl == '' || $onlymsg == 1) {
		$msg = "<script>alert(\"" . str_replace("\"", "��", $msg) . "\");</script>";
	} else {
		//当网址为:close::objname 时, 关闭父框架的id=objname元素
		if (eregi('close::', $gourl)) {
			$tgobj = trim(eregi_replace('close::', '', $gourl));
			$gourl = 'javascript:;';
			$func .= "window.parent.document.getElementById('{$tgobj}').style.display='none';\r\n";
		}

		$func .= "      var pgo=0;
				      function JumpUrl(){
				        if(pgo==0){ location='$gourl'; pgo=1; }
				      }\r\n";
		$rmsg = $func;
		$rmsg .= "document.write(\"<br /><div style='width:450px;padding:0px;border:1px solid #D1DDAA;'>";
		$rmsg .= "<div style='padding:6px;font-size:12px;border-bottom:1px solid #D1DDAA;background:#DBEEBD';'><b>duoduo提示信息</b></div>\");\r\n";
		$rmsg .= "document.write(\"<div style='height:130px;font-size:10pt;background:#ffffff'><br />\");\r\n";
		$rmsg .= "document.write(\"" . str_replace("\"", "“", $msg) . "\");\r\n";
		$rmsg .= "document.write(\"";

		if ($onlymsg == 0) {
			if ($gourl != 'javascript:;' && $gourl != '') {
				$rmsg .= "<br /><a href='{$gourl}'>如果你的浏览器没反应，请点击这里...</a>";
				$rmsg .= "<br/></div>\");\r\n";
				$rmsg .= "setTimeout('JumpUrl()',$litime);";
			} else {
				$rmsg .= "<br/></div>\");\r\n";
			}
		} else {
			$rmsg .= "<br/><br/></div>\");\r\n";
		}
		$msg = $htmlhead . $rmsg . $htmlfoot;
	}
	echo $msg;
}

function MkdirAll($truepath) {
	if (!file_exists($truepath)) {
		mkdir($truepath, 0777);
		chmod($truepath, 0777);
		return true;
	} else {
		return true;
	}
}

function judge_empty_dir($directory){      
    $handle = opendir($directory);      
    while (($file = readdir($handle)) !== false){          
        if ($file != "." && $file != ".."){              
            closedir($handle);              
            return 0;          
        }      
    }     
    closedir($handle);     
    return 1;  
}

function RpLine($str)
{
	$str = str_replace("\r","\\r",$str);
	$str = str_replace("\n","\\n",$str);
	return $str;
}

function get2var(){
	foreach($_GET as $k=>$v){
		global $$k;
		$$k=$v;
	}
}
function post2var(){
	foreach($_POST as $k=>$v){
		global $$k;
		$$k=$v;
	}
}
?>